package com.example.parkdemo.ping

import androidx.lifecycle.ViewModel
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import kotlinx.coroutines.flow.Flow

class PagingViewModel : ViewModel() {
    fun getPaging(): Flow<PagingData<Item>> {
        return Repo.getPagingData()
    }
}

object Repo {
    private const val PAGE_SIZE = 5
    private val apiService = ApiService.create()

    fun getPagingData(): Flow<PagingData<Item>> {
        return Pager(
            pagingSourceFactory = { RepoPagingSource(apiService) },
            config = PagingConfig(pageSize = PAGE_SIZE, prefetchDistance = PAGE_SIZE * 5)
        ).flow
    }
}